<?php
namespace app\index\controller;

use fast\Http;

require_once EXTEND_PATH.'/dd/TopSdk.php';
class Index
{
    protected $token_url = 'https://oapi.dingtalk.com/gettoken?appkey=%&appsecret=%';
    protected $appkey='dingrahq7azrrj6sl6vz';
    protected $appsecret = 'gAPTa8C3Juzo5lUmXg3YTlToTdkG6ZS2TIztc5JJGanJOuZSgGrzkJ4WgW8ErQlo';
//d796a3fcd9d03ae0b1189874a347c231

    public function index()
    {
        $webhook = "https://oapi.dingtalk.com/robot/send?access_token=2341f8950bcdb57a11a3c6cac2bb7c18a65a8d094875cac38e794f4a671ec3c9";
        $message="哇!金色传说";
        $data = array ('msgtype' => 'text','text' => array ('content' => $message));
        $data_string = json_encode($data);

        return $data;
}




    public function getAccessToken()
    {
        $data = ['appkey'=>$this->appkey,'appsecret'=>$this->appsecret];
        $res= self::post($data,$this->token_url);
        return $res;
    }


    public static function post($url,$data_string=null)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json;charset=utf-8'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码
        // curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
        // curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
}
